package fx.game.demo.common;

import javafx.scene.image.Image;
import javafx.scene.layout.*;

import java.net.URL;

/**
 *
 * @author: datom
 *
 * @create: 2021/12/5 23:16
 *
 * @Deprecated 游戏资源
 *
 **/
public class GameResource {

    /**
     * @Author: datom
     * @Date: 2021/12/5 23:17
     *
     * @Description: 获取重置按钮的背景图片
     *
     */
    public static Background getResetButtonIcon() {
        return getIcon("image/reset_icon.png", 40, 40);
    }

    /**
     * @Author: datom
     * @Date: 2021/12/6 14:33
     *
     * @Description: 获取色板图标
     *
     */
    public static Background getColorsIcon() {
        return getIcon("image/colors_icon.png", 40, 40);

    }

    /**
     * @Author: datom
     * @Date: 2021/12/6 17:39
     *
     * @Description: 获取确定按钮图标
     *
     */
    public static Background getConfirmIcon() {
        return getIcon("image/confirm_icon.png", 40, 40);
    }

    /**
     * @Author: datom
     * @Date: 2021/12/6 20:21
     *
     * @Description: 获取应用图标
     *
     */
    public static Image getAppIcon() {
        return getResource("image/app_icon.png");
    }

    /**
     * @Author: datom 
     * @Date: 2021/12/7 0:17
     * 
     * @Description: 关于按钮的图标
     *
     */
    public static Background getAboutIcon() {
        return getIcon("image/about_icon.png", 40, 40);
    }
    
    /**
     * @Author: datom 
     * @Date: 2021/12/6 20:15
     * 
     * @Description: 根据url获取背景图片
     *
     */
    public static Background getIcon(String path, double width, double height) {
        Image image = getResource(path);
        BackgroundSize backgroundSize = new BackgroundSize(width, height,
                false, false, true, false);


        BackgroundImage backgroundImage = new BackgroundImage(image,
                BackgroundRepeat.NO_REPEAT, BackgroundRepeat.NO_REPEAT,
                BackgroundPosition.CENTER, backgroundSize);

        Background background = new Background(backgroundImage);
        return background;
    }

    /**
     * @Author: datom
     * @Date: 2021/12/6 14:35
     *
     * @Description: 获取资源图片
     *
     */
    public static Image getResource(String path) {
        URL resource = getResourceUrl(path);

        if(resource != null) {
            return new Image(resource.toExternalForm());
        }else {
            return null;
        }
    }

    /**
     * @Author: datom
     * @Date: 2021/12/6 20:14
     *
     * @Description: 获取Resource文件夹下的文件URL
     *
     */
    public static URL getResourceUrl(String path) {
        return GameResource.class.getClassLoader()
                .getResource(path);
    }

}
